//
//  LSPlayTricksCell.m
//  LookScore
//
//  Created by wws on 2018/5/3.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.


#import "LSPlayTricksCell.h"
#import "LSChatPhotoView.h"
#import "EdgeInsetsLabel.h"

#define controlWidth (LSScreenWidth-LSSpaceLeftWidth1*2-20)/3
#define KBattlefieldCellHeight 228


#pragma mark 🔥 LSPlayTricksCell
@interface LSPlayTricksCell()

@property (nonatomic, strong) UILabel *contentLable;
@property (nonatomic, strong) UILabel *timeLable;
@property (nonatomic, strong) UILabel *styleLable;
@property (nonatomic, strong) UIButton *countBtn;

@property(nonatomic, strong) LSChatPhotoView * photoView;
@property(nonatomic, strong) UIImageView * hotImageView;

@end

@implementation LSPlayTricksCell
- (UILabel *)contentLable{
    if (!_contentLable) {
        _contentLable = [[UILabel alloc] init];
        _contentLable.text = @"防护撒发乎傅海峰好发货撒放坏事发生度阿辉阿段师傅爱上的活塞富二球飞洒会发怠";
        _contentLable.textColor = LSSubColor5D5D5D;
        _contentLable.font = LSFontSize(16, LSScreenWidth);
        _contentLable.numberOfLines = 2;
    }
    return _contentLable;
}
- (UILabel *)timeLable{
    if (!_timeLable) {
        _timeLable = [[UILabel alloc] init];
        _timeLable.textColor = LSTitleGrayColor3;
        _timeLable.font = LSFontSize(14, LSScreenWidth);
        _timeLable.textAlignment = NSTextAlignmentCenter;
        _timeLable.text = @"2018-04-28 11:33";
    }
    return _timeLable;
}
- (UILabel *)styleLable{
    if (!_styleLable) {
        _styleLable = [[UILabel alloc] init];
        _styleLable.textColor = LSTitleGrayColor3;
        _styleLable.font = LSFontSize(14, LSScreenWidth);
        _styleLable.text = @"官方小编";
    }
    return _styleLable;
}
- (UIButton *)countBtn{
    if (!_countBtn) {
        _countBtn = [[UIButton alloc] init];
        [_countBtn setTitle:@"1043" forState:UIControlStateNormal];
        [_countBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
        [_countBtn setImage:[UIImage imageNamed:@"PlayTricksLook"] forState:UIControlStateNormal];
        _countBtn.titleLabel.font = LSFontSize(14, LSScreenWidth);
    }
    return _countBtn;
}
- (UIImageView *)hotImageView{
    if (!_hotImageView) {
        _hotImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PlayTricksHot "]];
    }
    return _hotImageView;
}
+ (LSPlayTricksCell *)PlayTricksCellByTableView:(UITableView *)tableView{
    LSPlayTricksCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSPlayTricksCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    return self;
}

-(void)addContentView{
    
    [self.contentView addSubview:self.contentLable];
    self.contentLable.sd_layout
    .leftEqualToView(self.contentView).offset(LSAutoVlaue(15, LSScreenWidth))
    .topEqualToView(self.contentView).offset(LSAutoVlaue(10, LSScreenHeight))
    .rightEqualToView(self.contentView).offset(LSAutoVlaue(-15, LSScreenWidth))
    .heightIs(LSAutoVlaue(50, LSScreenHeight));
    
    
    _photoView = [[LSChatPhotoView alloc] init];
    [self.contentView addSubview:_photoView];
    _photoView.sd_layout
    .leftEqualToView(self.contentLable)
    .topSpaceToView(self.contentLable, 5); // 已经在内部实现宽度和高度自适应所以不需要再设置宽度高度，top值是具体有无图片在setModel方法中设置
    
    [self.contentView addSubview:self.styleLable];
    self.styleLable.sd_layout
    .leftEqualToView(self.photoView)
    .topSpaceToView(self.photoView, LSAutoVlaue(5, LSScreenHeight))
    .widthIs(LSAutoVlaue(60, LSScreenWidth))
    .heightIs(LSAutoVlaue(30, LSScreenHeight));
    
    
    [self.contentView addSubview:self.timeLable];
    self.timeLable.sd_layout
    .leftSpaceToView(self.styleLable, LSAutoVlaue(5, LSScreenWidth))
    .centerYEqualToView(self.styleLable)
    .widthIs(LSAutoVlaue(120, LSScreenWidth))
    .heightIs(LSAutoVlaue(30, LSScreenHeight));
    [self.timeLable setSingleLineAutoResizeWithMaxWidth:180];
    
    
    [self.contentView addSubview:self.countBtn];
    self.countBtn.sd_layout
    .rightEqualToView(self.contentLable)
    .centerYEqualToView(self.styleLable)
    .widthIs(LSAutoVlaue(80, LSScreenWidth))
    .heightIs(LSAutoVlaue(30, LSScreenHeight));
    
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = LSSubGrayColorf7;
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .bottomEqualToView(self.contentView).offset(-1)
    .heightIs(1);
    
}

- (void)setModel:(LSPlayTricksModel *)model{
    _model = model;
    self.contentLable.text = model.ArticleTitle;
//    if (model.ImgUrlStr.length <= 0) {
//
//        self.photoView.picPathStringsArray = @[];
//        //      self.adressBu.sd_resetLayout.leftEqualToView(self.headImageView).topSpaceToView(self.introduceLab,9).widthIs(60).heightIs(20);
//        //        self.photoView.hidden = YES;
//    }else{
//        NSArray * array = [model.ImgUrlStr componentsSeparatedByString:@","];
//        self.photoView.picPathStringsArray = array;
//    }
//    self.adressBu.sd_resetLayout.leftEqualToView(self.headImageView).topSpaceToView(self.photoView,9).widthIs(60).heightIs(20);
//
//    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"]];
//    self.nameLab.text = model.UserDisName;
//
//    self.introduceLab.text = model.TopicContent;
//
//    [self.adressBu setTitle:model.CircleName forState:UIControlStateNormal];
//    NSString * timeStr = [model.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
//
//    NSDateFormatter * df = [[NSDateFormatter alloc] init];
//    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
//    NSString * dateString1 = timeStr;
//    NSString * dateString2 = [CommonClass getCurrentTimes];
//    NSDate * date1 = [df dateFromString:dateString1];
//    NSDate * date2 = [df dateFromString:dateString2];
//    NSTimeInterval time = [date2 timeIntervalSinceDate:date1]; //date1是前一个时间(早)，date2是后一个时间(晚)
//    // 结果就是两个时间点之间相差的秒数，如果要精确时间，修改NSDateFormatter的形式，并把两个时间对应调整就行
//    if (time < 300) {
//
//        self.timeLab.text = @"刚刚";
//    }else{
//        self.timeLab.text = [CommonClass timestampToString:model.TimeStamp];
//
//    }
//
//
//    [self.browseBu setTitle:[NSString stringWithFormat:@"%ld",model.ReadCount] forState:UIControlStateNormal];
//
//    [self.commentBu setTitle:[NSString stringWithFormat:@"%ld",model.CommentCount] forState:UIControlStateNormal];
//
//    [self.praiseBu setTitle:[NSString stringWithFormat:@"%ld",model.ThumbupCount] forState:UIControlStateNormal];
//
//    if (model.IsAttended) {
//        self.attentionBu.selected = YES;
//    }else{
//        self.attentionBu.selected = NO;
//    }
//    self.browseBu.hidden = YES;
//    if (model.MatchId > 0) {
//
//        _gameLabel.hidden = NO;
//        _gameLabel.text = [NSString stringWithFormat:@"%@ vs %@",model.HomeTeamName,model.GuestTeamName];
//        self.timeLab.sd_resetLayout
//        .leftSpaceToView(_gameLabel, 5)
//        .centerYEqualToView(_gameLabel)
//        .autoHeightRatio(0);
//        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
//    }else{
//
//        //        self.browseBu.hidden = NO;
//        _gameLabel.hidden = YES;
//        self.timeLab.sd_resetLayout
//        .leftSpaceToView(self.adressBu, 5)
//        .centerYEqualToView(self.adressBu)
//        .autoHeightRatio(0);
//        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
//    }
}
- (void)setQueryCircleId:(NSInteger)queryCircleId{
    
    //    _queryCircleId = queryCircleId;
    //    if (queryCircleId == 0) {
    //        self.browseBu.hidden = YES;
    //        _gameLabel.hidden = NO;
    //        self.timeLab.sd_resetLayout
    //        .leftSpaceToView(_gameLabel, 5)
    //        .centerYEqualToView(_gameLabel)
    //        .autoHeightRatio(0);
    //        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
    //    }else{
    //        self.browseBu.hidden = NO;
    //        _gameLabel.hidden = YES;
    //        self.timeLab.sd_resetLayout
    //        .leftSpaceToView(self.adressBu, 5)
    //        .centerYEqualToView(self.adressBu)
    //        .autoHeightRatio(0);
    //        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
    //    }
    
}


@end


#pragma mark 🔥 LSTricksOneImageCell
@interface LSTricksOneImageCell()

@property (nonatomic, strong) UILabel *contentLable;
@property (nonatomic, strong) UILabel *timeLable;
@property (nonatomic, strong) UILabel *styleLable;
@property (nonatomic, strong) UIButton *countBtn;

@property(nonatomic, strong) UIImageView * contentImage;
//@property(nonatomic, strong) LSChatPhotoView * photoView;
@property(nonatomic, strong) UIImageView * hotImageView;

@end

@implementation LSTricksOneImageCell
- (UILabel *)contentLable{
    if (!_contentLable) {
        _contentLable = [[UILabel alloc] init];
        _contentLable.textColor = LSSubColor0B0B0B;
        _contentLable.font = LSFontSize(18, LSScreenWidth);
        _contentLable.numberOfLines = 3;
    }
    return _contentLable;
}
- (UILabel *)timeLable{
    if (!_timeLable) {
        _timeLable = [[UILabel alloc] init];
        _timeLable.textColor = LSTitleGrayColor3;
        _timeLable.font = LSFontSize(14, LSScreenWidth);
        _timeLable.textAlignment = NSTextAlignmentCenter;
    }
    return _timeLable;
}
- (UILabel *)styleLable{
    if (!_styleLable) {
        _styleLable = [[UILabel alloc] init];
        _styleLable.text = @"官方小编";
        _styleLable.textColor = LSTitleGrayColor3;
        _styleLable.font = LSFontSize(14, LSScreenWidth);
    }
    return _styleLable;
}
- (UIButton *)countBtn{
    if (!_countBtn) {
        _countBtn = [[UIButton alloc] init];
        [_countBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
        [_countBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
        [_countBtn setImage:[UIImage imageNamed:@"PlayTricksLook"] forState:UIControlStateNormal];
        _countBtn.titleLabel.font = LSFontSize(14, LSScreenWidth);
    }
    return _countBtn;
}
- (UIImageView *)contentImage{
    if (!_contentImage) {
        _contentImage = [[UIImageView alloc] init];
    }
    return _contentImage;
}
- (UIImageView *)hotImageView{
    if (!_hotImageView) {
        _hotImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PlayTricksHot"]];
    }
    return _hotImageView;
}
+ (LSTricksOneImageCell *)TricksOneImageCellByTableView:(UITableView *)tableView{
    LSTricksOneImageCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSTricksOneImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    return self;
}

-(void)addContentView{
    
    [self.contentView addSubview:self.contentLable];
    self.contentLable.sd_layout
    .leftEqualToView(self.contentView).offset(LSAutoVlaue(15, LSScreenWidth))
    .topEqualToView(self.contentView).offset(LSAutoVlaue(18, LSScreenHeight))
//    .bottomEqualToView(self.contentView).offset(LSAutoVlaue(-40, LSScreenHeight))
    .widthIs(LSAutoVlaue(209, LSScreenWidth))
    .heightIs(LSAutoVlaue(68, LSScreenHeight));
    
    
//    _photoView = [[LSChatPhotoView alloc] init];
//    [self.contentView addSubview:_photoView];
//    _photoView.sd_layout
//    .leftEqualToView(self.contentLable)
//    .topSpaceToView(self.contentLable, 5); // 已经在内部实现宽度和高度自适应所以不需要再设置宽度高度，top值是具体有无图片在setModel方法中设置
    [self.contentView addSubview:self.contentImage];
    self.contentImage.sd_layout
    .rightEqualToView(self.contentView).offset(LSAutoVlaue(-15, LSScreenWidth))
    .topEqualToView(self.contentView).offset(LSAutoVlaue(16, LSScreenHeight))
    .widthIs(LSAutoVlaue(113, LSScreenWidth))
    .heightIs(LSAutoVlaue(74, LSScreenHeight));
    
    [self.contentView addSubview:self.hotImageView];
    self.hotImageView.sd_layout
    .leftEqualToView(self.contentLable)
    .topSpaceToView(self.contentLable, LSAutoVlaue(15, LSScreenHeight))
    .widthIs(LSAutoVlaue(25, LSScreenWidth))
    .heightIs(LSAutoVlaue(20, LSScreenHeight));
    
    
    [self.contentView addSubview:self.styleLable];
    self.styleLable.sd_layout
    .leftSpaceToView(self.hotImageView, 5)
    .topSpaceToView(self.contentLable, LSAutoVlaue(10, LSScreenHeight))
    .bottomEqualToView(self.contentView).offset(LSAutoVlaue(-15, LSScreenHeight))
    .widthIs(LSAutoVlaue(60, LSScreenWidth));
    
    
    [self.contentView addSubview:self.timeLable];
    self.timeLable.sd_layout
    .leftSpaceToView(self.styleLable, LSAutoVlaue(5, LSScreenWidth))
    .centerYEqualToView(self.styleLable)
    .widthIs(LSAutoVlaue(120, LSScreenWidth))
    .heightIs(LSAutoVlaue(30, LSScreenHeight));
    [self.timeLable setSingleLineAutoResizeWithMaxWidth:180];
    
    
    [self.contentView addSubview:self.countBtn];
    self.countBtn.sd_layout
    .rightEqualToView(self.contentImage)
    .centerYEqualToView(self.styleLable)
    .widthIs(LSAutoVlaue(80, LSScreenWidth))
    .heightIs(LSAutoVlaue(30, LSScreenHeight));
    
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = LSSubGrayColorf7;
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .bottomEqualToView(self.contentView)
    .heightIs(1);
    
}

- (void)setModel:(LSPlayTricksModel *)model{
    _model = model;
    self.contentLable.text = model.ArticleTitle;
    [self.contentImage sd_setImageWithURL:[NSURL URLWithString:model.ListImgUrl] placeholderImage:[UIImage imageNamed:@"MineHead"] options:SDWebImageRefreshCached];
    [self.countBtn setTitle:model.IpReadCount forState:UIControlStateNormal];
    self.timeLable.text = [model.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    if (model.IsRedMark) {
        self.hotImageView.hidden = NO;
        self.styleLable.sd_layout
        .leftSpaceToView(self.hotImageView, 5)
        .topSpaceToView(self.contentLable, LSAutoVlaue(10, LSScreenHeight))
        .bottomEqualToView(self.contentView).offset(LSAutoVlaue(-15, LSScreenHeight))
        .widthIs(LSAutoVlaue(60, LSScreenWidth));
    }else{
        self.hotImageView.hidden = YES;
        self.styleLable.sd_layout
        .leftEqualToView(self.contentLable)
        .topSpaceToView(self.contentLable, LSAutoVlaue(10, LSScreenHeight))
        .bottomEqualToView(self.contentView).offset(LSAutoVlaue(-15, LSScreenHeight))
        .widthIs(LSAutoVlaue(60, LSScreenWidth));
    }
    
}
- (void)setQueryCircleId:(NSInteger)queryCircleId{
    
    //    _queryCircleId = queryCircleId;
    //    if (queryCircleId == 0) {
    //        self.browseBu.hidden = YES;
    //        _gameLabel.hidden = NO;
    //        self.timeLab.sd_resetLayout
    //        .leftSpaceToView(_gameLabel, 5)
    //        .centerYEqualToView(_gameLabel)
    //        .autoHeightRatio(0);
    //        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
    //    }else{
    //        self.browseBu.hidden = NO;
    //        _gameLabel.hidden = YES;
    //        self.timeLab.sd_resetLayout
    //        .leftSpaceToView(self.adressBu, 5)
    //        .centerYEqualToView(self.adressBu)
    //        .autoHeightRatio(0);
    //        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
    //    }
    
}


@end
